
local MainScene = class("MainScene", cc.load("mvc").ViewBase)


function MainScene:onCreate()
    -- 添加背景图片
    display.newSprite("background.png")
        :move(display.center)
        :addTo(self)

    -- "游戏名称"
    local pText = cc.Label:createWithSystemFont("飞机大战", "Arial", 40)
        :move(display.cx, display.cy + 200)
        :addTo(self)


    -- 飞机
    self.m_pPlane = display.newSprite("hero1.png")
        :move(display.cx,display.cy )
        :addTo(self)

    -- 游戏开始的按钮
    local pStartButton = display.newSprite("btn_finish.png")
        :move(display.cx, display.cy - 200)
        :addTo(self)

    local action1 = cc.MoveBy:create(0.5,cc.p(0,20))
    local action2 = cc.MoveBy:create(0.5, cc.p(0, -20))
    local sequence = cc.Sequence:create(action1, action2)
    local repeatForever = cc.RepeatForever:create(sequence)
    transition.execute(self.m_pPlane, repeatForever)

    -- 点击回到游戏按钮
    local function onTouchBegan(touch, event)
        return true
    end
    local function onTouchMoved(touch, event)
        return true
    end
    --进入到了新的场景
    local function onTouchEnded(touch, event)
        self:getApp():enterScene("GameScene", "ZOOMFLIPANGULAR", 1.0, nil)
        return true
    end
    -- 这一坨我也不知道啥意思 反正不这么写就显示不出来,进入不了新的场景
    local eventListener = cc.EventListenerTouchOneByOne:create()
    eventListener:setSwallowTouches(true)
    eventListener:registerScriptHandler(onTouchBegan, cc.Handler.EVENT_TOUCH_BEGAN)
    eventListener:registerScriptHandler(onTouchMoved, cc.Handler.EVENT_TOUCH_MOVED)
    eventListener:registerScriptHandler(onTouchEnded, cc.Handler.EVENT_TOUCH_ENDED)

    local eventDispatcher = pStartButton:getEventDispatcher()
    eventDispatcher:addEventListenerWithSceneGraphPriority(eventListener, pStartButton)


    for k,v in pairs(debug.getinfo(print)) do
        print(k,v)
    end
end

return MainScene
